<div class="layui-fluid">
  <div class="layui-row">
    <form action="" method="post" class="layui-form layui-form-pane">
      <div class="layui-form-item">
        <label class="layui-form-label">
          <span class="x-red">*</span>房产
        </label>
        <div class="layui-input-inline">
          <input type="text" id="" name="" value="{$property_name}" required=""
            lay-verify="required" autocomplete="off" class="layui-input" readonly style="background-color: #eeeeee;">
        </div>
      </div>
      {foreach $data as $v}
      <div class="layui-form-item">
        {if $type==='e'}
        <label for="{$v.id}" class="layui-form-label">
          {$v.name}--{$v.electricity_meter_last_month}
        </label>
        <div class="layui-input-inline">
          <input type="text" id="{$v.id}" name="{$v.id}" value="{$v.electricity_meter_this_month}" lay-verify="vnum"
          autocomplete="off" class="layui-input">
        </div>
        {elseif $type==='w'}
        <label for="{$v.id}" class="layui-form-label">
          {$v.name}--{$v.water_meter_last_month}
        </label>
        <div class="layui-input-inline">
          <input type="text" id="{$v.id}" name="{$v.id}" value="{$v.water_meter_this_month}" lay-verify="vnum"
          autocomplete="off" class="layui-input">
        </div>
        {/if}
      </div>
      {/foreach}
      <div class="layui-form-item">
        <button class="layui-btn" lay-submit="" lay-filter="save">保存</button>
      </div>
    </form>
  </div>
</div>

<script>
  layui.use(['form', 'layer', 'laydate'], function () {
    $ = layui.jquery;
    var form = layui.form
      , layer = layui.layer;

    //自定义验证规则
    form.verify({
      vnum: [/(^$)|^\d+$/,'只能填写数字']
    });

    //监听提交
    form.on('submit(save)', function (data) {
      //发异步，把数据提交给php
      main.ajaxPost(
        {
          url: "{:url('saveCentralized')}",
          data: {"data":data.field, "type": "{$type}"},
        },
        function (data) {
          setTimeout(function () {
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            //表格重载
            parent.layui.table.reload('dataGrid');
            //关闭当前frame 
            parent.layer.close(index);
          }, 1000);
        }
      )
      return false;
    });
  });
</script>